use std::io::{Read, Result as IoResult};

pub struct StrsAsRead<'a> {
    src_lst: &'a [&'a str],
}

impl<'a> StrsAsRead<'a> {
    pub fn new(src_lst: &'a [&'a str]) -> Self {
        Self { src_lst }
    }
}

impl<'a> Read for StrsAsRead<'a> {
    fn read(&mut self, mut buf: &mut [u8]) -> IoResult<usize> {
        let mut n = 0;
        while let Some(src) = self.src_lst.first() {
            let d = src.len().min(buf.len());
            buf[..d].copy_from_slice(src[..d].as_bytes());

            n += d;
            buf = &mut buf[d..];
            if d == src.len() {
                self.src_lst = &self.src_lst[1..];
            }
        }
        Ok(n)
    }
}
